#ifdef TEST
#include <string>
#include <vector>
#include "Emulator.h"
#include "Functions.h"

using namespace std;


#include <cfixcc.h>

class ExampleTest : public cfixcc::TestFixture
{
public:
  
  void testTrimFunction() {
    string trimStr = getTrimLine("   ");
    CFIXCC_ASSERT_EQUALS(trimStr == "", true);
    trimStr = getTrimLine("abc");
    CFIXCC_ASSERT_EQUALS(trimStr == "abc", true);
    trimStr = getTrimLine("    abc");
    CFIXCC_ASSERT_EQUALS(trimStr == "abc", true);
    trimStr = getTrimLine("    abc    ");
    CFIXCC_ASSERT_EQUALS(trimStr == "abc", true);
    trimStr = getTrimLine("abc    ");
    CFIXCC_ASSERT_EQUALS(trimStr == "abc", true);
    trimStr = getTrimLine("abc  sde");
    CFIXCC_ASSERT_EQUALS(trimStr == "abc  sde", true);
    trimStr = getTrimLine("    abc  sde");
    CFIXCC_ASSERT_EQUALS(trimStr == "abc  sde", true);
    trimStr = getTrimLine("abc  sde    ");
    CFIXCC_ASSERT_EQUALS(trimStr == "abc  sde", true);
    trimStr = getTrimLine("    abc  sde    ");
    CFIXCC_ASSERT_EQUALS(trimStr == "abc  sde", true);
  }
  
  void numberOfProgramError_programCountInFirstLineIsBiggerThenNeed() {
    processFile("../Tests/in_e1.txt", "../Tests/out.txt");
  }
  
  void numberOfProgramError_programCountInFirstLineIsLessThenNeed() {
    processFile("../Tests/in_e1.txt", "../Tests/out.txt");
  }
  
  void firstLineError_firstLineCountainsNotNumbers() {
    processFile("../Tests/in_fe1.txt", "../Tests/out.txt");
  }
  
  void firstLineError_firstLineContainsDigitsLessThenNeed() {
    processFile("../Tests/in_fe2.txt", "../Tests/out.txt");
  }

  
  void variableNameError_usingOfUnknownVariable() {    
    processFile("../Tests/in_n1.txt", "../Tests/out.txt");
  }

  
  void mainTest() {
    processFile("../Tests/in.txt", "../Tests/out.txt");

    CFIXCC_ASSERT_EQUALS(InfoAnalizer::getNumberOfPrograms(), 3);
    CFIXCC_ASSERT_EQUALS(InfoAnalizer::getTimeQuantumSize(), 1);    

    checkFileEqual("../Tests/out.txt", "../Tests/in_.txt");
  }  

  void checkFileEqual(const string &fileName1, const string &fileName2) {
    vector<string> lines1;
    getFileLinesTemplate(fileName1, lines1);
    vector<string> lines2;
    getFileLinesTemplate(fileName2, lines2);
    CFIXCC_ASSERT_EQUALS(lines1.size(), lines2.size());    
    for (int i = 0; i < lines1.size(); i++) {
      CFIXCC_ASSERT_EQUALS(lines1[i], lines2[i]);
    }
  }

  void mainTest2() {
    processFile("../Tests/in2.txt", "../Tests/out.txt");

    CFIXCC_ASSERT_EQUALS(InfoAnalizer::getNumberOfPrograms(), 3);
    CFIXCC_ASSERT_EQUALS(InfoAnalizer::getTimeQuantumSize(), 3);    


    checkFileEqual("../Tests/out.txt", "../Tests/in2_.txt");
  }  
};

CFIXCC_BEGIN_CLASS( ExampleTest )
  CFIXCC_METHOD(mainTest)  
  CFIXCC_METHOD(mainTest2)  
  CFIXCC_METHOD(testTrimFunction)  
  CFIXCC_METHOD_EXPECT_EXCEPTION(numberOfProgramError_programCountInFirstLineIsBiggerThenNeed, std::logic_error)
  CFIXCC_METHOD_EXPECT_EXCEPTION(numberOfProgramError_programCountInFirstLineIsLessThenNeed, std::logic_error)
  CFIXCC_METHOD_EXPECT_EXCEPTION(variableNameError_usingOfUnknownVariable, std::logic_error)
  CFIXCC_METHOD_EXPECT_EXCEPTION(firstLineError_firstLineCountainsNotNumbers, std::logic_error)
  CFIXCC_METHOD_EXPECT_EXCEPTION(firstLineError_firstLineContainsDigitsLessThenNeed, std::logic_error)
  CFIXCC_END_CLASS()
#endif